package ydzhao.weixin.tuisong.util;

import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author chlong
 * @date 2022/8/12
 */

public class WeixinUtil {

    private static String key = "xxx";

    /**
     * 智能机器人自动回复
     * @param question
     * @return
     */
    public String randomReply(String question){
        String url = "http://api.tianapi.com/robot/index?key=" + key + "&question=" + question;
        //猜谜底
        String content = "";
        try {
            JSONObject jsonObject = JSONObject.parseObject(HttpUtil.getUrl(url));
            if (jsonObject.getIntValue("code") == 200) {
                content = jsonObject.getJSONArray("newslist").getJSONObject(0).getString("reply");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return content;
    }
}
